package com.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.po.SysServer;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Date;
import java.util.List;


@Mapper
public interface SysServerMapper extends BaseMapper<SysServer> {

    @Select(value = "select id from sys_server where refresh_time <#{lastTime} and is_active = 1 and id <> #{id}")
    public List<Long> getDownServerList(@Param("lastTime") Date lastTime, @Param("id") Long id);

    @Select(value = "select id from sys_server where is_active = 1")
    public List<Long> getActiveServerKeys();

    @Select(value = "select * from sys_server where is_active = 1")
    public List<SysServer> getActiveServers();

    @Update("<script>" + " update sys_server set is_active = 0 , down_time = #{nowTime} where id in (" + " <foreach collection='ids' separator=',' item='id'>" + " #{id} " + " </foreach> " + " )</script>")
    public void updateServerStatus(@Param("nowTime") Date nowTime, @Param("ids") List<Long> ids);
}
